package top.heliming.rabbitmq.rabbitmqdemo.direct;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import top.heliming.rabbitmq.rabbitmqdemo.util.ConnectionUtil;
/**
 * description: //订阅模式：生产者指定路由key
 *
 * @author: heliming
 * @date:2019/06/07 上午 10:24
 */
public class Send5 {

  private final static String EXCHANGE_NAME = "direct_exchange_test";

  public static void main(String[] argv) throws Exception {
    // 获取到连接
    Connection connection = ConnectionUtil.getConnection();
    // 获取通道
    Channel channel = connection.createChannel();
    // 声明exchange，指定类型为direct
    channel.exchangeDeclare(EXCHANGE_NAME, "direct");
    // 消息内容
    String message = "商品新增了， id = 1001";
    String messageupdate = "商品修改了， id = 1001";
    String messagedel = "商品删除了， id = 1001";
    // 发送消息，并且指定routing key 为：insert ,代表新增商品
    channel.basicPublish(EXCHANGE_NAME, "insert", null, message.getBytes());
    channel.basicPublish(EXCHANGE_NAME, "update", null, messageupdate.getBytes());
    channel.basicPublish(EXCHANGE_NAME, "delete", null, messagedel.getBytes());
    System.out.println(" [商品服务：] Sent '" + message + "'");

    channel.close();
    connection.close();
  }
}
